#include "transform.h"
#include <math.h>
static float mysin(float v){
    return sinf(v);
}
static float mycos(float v){
    return cosf(v);
}
static mat3x3* m33_translation_make(mat3x3* out, float x, float y)
{
    mat3x3_one(out);
    out->m[2][0] = x;
    out->m[2][1] = y;
    return out;
}
static mat3x3* m33_scale_make(mat3x3* out, float sx, float sy)
{
    mat3x3_one(out);
    out->m[0][0] = sx;
    out->m[1][1] = sy;
    return out;
}
static mat3x3* m33_rotate_make(mat3x3* out, float angle)
{
    mat3x3_one(out);
    float sin_v = mysin(radians(angle));
    float cos_v = mycos(radians(angle));
    out->m[0][0] = cos_v;
    out->m[0][1] = sin_v;
    out->m[1][0] = -sin_v;
    out->m[1][1] = cos_v;
    return out;
}

mat3x3* m33_translation_copy(mat3x3* out, const mat3x3* m33, float dx, float dy)
{
    mat3x3 trans;
    m33_translation_make(&trans, dx, dy);
    return mat3x3_mult_mat3x3_copy(out, m33, &trans);
}

mat3x3* m33_translation(mat3x3* m33, float dx, float dy)
{
    mat3x3 out;
    return mat3x3_copy(m33, m33_translation_copy(&out, m33, dx, dy));
}

mat3x3* m33_rotate_copy(mat3x3* out, const mat3x3* m33, float angle)
{
    mat3x3 rota;
    m33_rotate_make(&rota, angle);
    return mat3x3_mult_mat3x3_copy(out, m33, &rota);
}
mat3x3* m33_rotate(mat3x3* m33, float angle)
{
    mat3x3 out;
    return mat3x3_copy(m33, m33_rotate_copy(&out, m33, angle));
}
mat3x3* m33_scale_copy(mat3x3* out, const mat3x3* m33, float sx, float sy)
{
    mat3x3 scal;
    m33_scale_make(&scal, sx, sy);
    return mat3x3_mult_mat3x3_copy(out, m33, &scal);
}
mat3x3* m33_scale(mat3x3* m33, float sx, float sy)
{
    mat3x3 out;
    return mat3x3_copy(m33, m33_scale_copy(&out, m33, sx, sy));
}
